/**
 * Created by Forcs on 16/4/14.
 */

var Router = require('express').Router;

var BaseController = function () {
  this.$router = new Router();
  this.$router.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With');
    res.setHeader('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS');
    next();
  });
};

BaseController.prototype.onCreate = function () {
};

BaseController.prototype.onStart = function () {
};

BaseController.prototype.onRouting = function (router) {
  return router;
};

BaseController.prototype.router = function () {
  var router = this.onRouting(this.$router);
  if (router !== undefined) {
    this.$router = router;
  }
  return this.$router;
};

module.exports = BaseController;